package com.hsp.poly_.Polyarr;

public class PolyArray {
    public static void main(String[] args) {
        //应用实例：现有一个继承结构如下：要求创建1个Person对象
        //2个Student 对象和2个Teacher对象，统一放在数组中，并调用每个对象say方法
        Person[] persons = new Person[5];
        persons[0] = new Person("jack",20);
        persons[1] = new Student("mary", 19, 100);
        persons[2] = new Student("smi th", 19, 30.1);
        persons[3] = new Teacher("scott", 30, 20000);
        persons[4] = new Teacher("king", 50, 25000);
        for (int i = 0; i < persons.length; i++) {
            System.out.println(persons[i].say());
            if (persons[i] instanceof Teacher) {
                Teacher teacher = (Teacher) persons[i];
                teacher.teach();
            }
            else if(persons[i] instanceof Student) {
                Student student = (Student) persons[i];
                student.study();
        }
            else if(persons[i] instanceof Person){
            }
            else{
                System.out.println("你的类型有误，请检查");
            }
        }
    }
}
